package com.sttg.csp.registration.action;

import java.util.HashMap;
import java.util.Map;
import com.sttg.csp.common.action.PagedAction;
import com.sttg.csp.common.consts.SystemConst;
import com.sttg.csp.common.exception.BizException;
import com.sttg.csp.registration.service.LogManageService;

public class LogManageAction extends PagedAction {

	private LogManageService logManageService = LogManageService.getInstance();

	private Map model = new HashMap();

	public LogManageAction() {
	}

	// show Index page
	public String showIndex() throws Exception {
		return INDEX;
	}

	// query list of B/D administrators.
	public String queryPagedList() throws Exception {
		try {
			logManageService.queryPagedList(model, pagedRecords);
		} catch (BizException e) {
			this.addActionError(e.getMessage());
			return ERROR;
		}
		return LIST;
	}

	// show detail of a B/D administrator
	public String showInfo() throws Exception {
		try {
			model = logManageService.queryObject(model);
			if (model == null) {
				this.addActionError("The record no found in db!");
				return ERROR_PAGE;
			}
		} catch (BizException e) {
			this.addActionError(e.getMessage());
			return ERROR_PAGE;
		}
		setOperationType(SystemConst.OPERATION_TYPE_VIEW);
		return INFO;
	}

	// show page for adding a B/D administrator
	public String showAdd() throws Exception {
		setOperationType(SystemConst.OPERATION_TYPE_NEW);
		return INPUT;
	}

	public String doInsert() throws Exception {
		try {
			logManageService.doInsert(model);
		} catch (BizException e) {
			this.addActionError(e.getMessage());
			return ERROR;
		}
		return NONE;
	}

	public String showEdit() throws Exception {
		try {
			model = logManageService.queryObject(model);
			if (model == null) {
				this.addActionError("The record no found in db!");
				return ERROR_PAGE;
			}
		} catch (BizException e) {
			this.addActionError(e.getMessage());
			return ERROR_PAGE;
		}

		setOperationType(SystemConst.OPERATION_TYPE_MODIFY);
		return INPUT;
	}

	// perform to delete a Log.
	public String doDelete() throws Exception {
		try {
			logManageService.doDelete(model);
		} catch (BizException e) {
			this.addActionError(e.getMessage());
			return ERROR;
		}
		return NONE;
	}

	public void setModel(Map model) {
		this.model = model;
	}

	public Map getModel() {
		return model;
	}
}
